<script setup lang="ts">
import { onMounted, ref } from 'vue'

const {
    title = '默认标题',
    text = '默认内容',
    confirmCallback,
    cancelCallback
} = defineProps<{
    title?: string // 标题
    text?: string // 内容
    confirmCallback: () => void // 确定
    cancelCallback: () => void // 取消
}>()

// 动画
const isShow = ref(false)
onMounted(() => {
    setTimeout(() => {
        isShow.value = true
    }, 200)
})


// 点了取消
const cancel = () => {
    isShow.value = false
    setTimeout(() => {
        cancelCallback()
    }, 0)
}


</script>

<template>
    <div class="xtx-confirm" :class="{ fade: isShow }">
        <div class="confirm-box" :class="{ fade: isShow }">
            <div class="header">
                <p>{{ title }}</p>
                <a @click="cancelCallback" href="JavaScript:;" class="iconfont icon-close-new"></a>
            </div>
            <div class="body">
                <p>{{ text }}</p>
            </div>
            <div class="footer">
                <button @click="cancel">取消</button>
                <button @click="confirmCallback">确定</button>
            </div>
        </div>
    </div>
</template>

<style lang="less" scoped>
.xtx-confirm {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 8887;
    background: rgba(0, 0, 0, 0);
    transition: all .7s;

    &.fade {
        background: rgba(0, 0, 0, .5);

    }

    .confirm-box {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 400px;
        height: 160px;
        background-color: #f5f5f5;
        transition: all .7s;
        opacity: 0;

        &.fade {
            opacity: 1;

        }

        .header {
            display: flex;
            justify-content: space-between;
            padding: 8px 10px 0;
            font-size: 18px;
            font-weight: 500;

            a {
                font-size: 22px;
            }
        }

        .body {
            display: flex;
            align-items: center;
            height: 75px;
            width: 100%;
            flex-wrap: wrap;
            padding-left: 50px;
        }

        .footer {
            padding: 10px 10px 0 0;

            button {
                float: right;
                width: 62px;
                height: 25px;
                border: none;
                outline: none;
                background: @xtxColor;
                text-align: center;
                border: 1px solid transparent;
                border-radius: 4px;
                cursor: pointer;

                &:nth-child(1) {
                    margin-left: 5px;
                    background: blanchedalmond;
                }
            }


        }

    }
}
</style>